Trickle in a bit of Garmin/USB support that isn't disruptive.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 31 Aug 2004 20:54:23 +0000 (20:54 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 31 Aug 2004 20:54:23 +0000 (20:54 +0000)
gpsbabel/jeeps/garminusb.h [new file with mode: 0644]
gpsbabel/jeeps/gps.h
gpsbabel/jeeps/gpsapp.c

diff --git a/gpsbabel/jeeps/garminusb.h b/gpsbabel/jeeps/garminusb.h
new file mode 100644 (file)
index 0000000..2a063a9
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+    Definitions for Garmin USB protocol and implementation.
+
+    Copyright (C) 2004 Robert Lipe, robertlipe@usa.net
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
+
+ */
+#include <stdio.h>
+
+/* This structure is a bit funny looking to avoid variable length
+ * arrays which aren't present in C89.   This contains the visible
+ * fields in the USB packets of the Garmin USB receivers (60C, 76C, etc.)
+ * All data are little endian. 
+ */
+typedef 
+union {
+       struct {
+       unsigned char type;
+       unsigned char reserved1;
+       unsigned char reserved2;
+       unsigned char reserved3;
+       unsigned char pkt_id[2];
+       unsigned char reserved6;
+       unsigned char reserved7;
+       unsigned char datasz[4];
+       unsigned char databuf[1]; /* actually an variable length array... */
+       } gusb_pkt;
+       unsigned char dbuf[MAX_GPS_PACKET_SIZE];
+} garmin_usb_packet;
+
+/*
+ * Internal interfaces that are common regardless of underlying 
+ * OS implementation. 
+ */
+#define GUSB_MAX_UNITS 20
+struct {
+       unsigned long serial_number;
+       char *os_identifier; /* In case the OS has another name for it. */
+       char *product_identifier; /* From the hardware itself. */
+} garmin_unit_info[GUSB_MAX_UNITS];
+
+int gusb_cmd_send(const garmin_usb_packet *obuf, size_t sz);
+int gusb_cmd_get(garmin_usb_packet *ibuf, size_t sz);
+int gusb_open(const char *portname);
+int gusb_close(void);
index 746092bc9349303582d3db46ecac1e3cbe99e169..8abd464db5e97baa6e8c425725e3fa1b06a77371 100644 (file)
@@ -177,6 +177,7 @@ double gps_save_lon;
 extern int32  gps_save_id;
 extern double gps_save_version;
 extern char   gps_save_string[GPS_ARB_LEN];
+extern int gps_is_usb;
 
 
 extern struct COMMANDDATA COMMAND_ID[2];
index 594d60e093e0bde381311dc0cfb906cc4a618df0..9322b082a01df176c5820934452ca3b9c7f5625b 100644 (file)
@@ -97,9 +97,10 @@ static void   GPS_D550_Send(UC *data, GPS_PAlmanac alm);
 static void   GPS_D551_Send(UC *data, GPS_PAlmanac alm);
 
 
-int32    gps_save_id;
-double gps_save_version;
-char  gps_save_string[GPS_ARB_LEN];
+int32  gps_save_id;
+int    gps_is_usb;
+double gps_save_version;
+char   gps_save_string[GPS_ARB_LEN];
 
 
 /* @func GPS_Init ******************************************************
@@ -118,9 +119,16 @@ int32 GPS_Init(const char *port)
     int32 ret;
     
     (void) GPS_Util_Little();    
+
+    /*
+     *  Decide here if the portname refers to a USB device and set the 
+     *  global that's used as in inflection point for other decisions later.
+     */
+    gps_is_usb = (0 == strncmp(port, "usb:", 4));
+
     ret = GPS_A000(port);
     if(ret<0) return ret;
-    
+    if (gps_is_usb) return 1;    
     gps_save_time = GPS_Command_Get_Time(port);
     if(!gps_save_time) {
        return FRAMING_ERROR;
@@ -154,12 +162,12 @@ static int32 GPS_A000(const char *port)
     if(!GPS_Serial_On(port, &fd))
        return gps_errno;
 
-    if(!GPS_Serial_Flush(fd))
+    if(!gps_is_usb && !GPS_Serial_Flush(fd))
        return gps_errno;
 
     if(!(tra = GPS_Packet_New()) || !(rec = GPS_Packet_New()))
        return MEMORY_ERROR;
-    
+
     GPS_Make_Packet(&tra, LINK_ID[0].Pid_Product_Rqst,NULL,0);
     if(!GPS_Write_Packet(fd,tra))
        return SERIAL_ERROR;
@@ -182,8 +190,6 @@ static int32 GPS_A000(const char *port)
     (void) sprintf(tstr,
                   "Version:\t%.2f\n",gps_save_version);
     GPS_User(tstr);
-    
-    
 
 
     gps_date_time_transfer = pA600;